import psycopg2

# 定义数据库连接参数
db_params = {
    'host': 'localhost',
    'port': 15432,
    'database': 'postgres',
    'user': 'postgres',
    'password': 'abc12345678'
}

# 连接到 PostgreSQL 数据库
try:
    connection = psycopg2.connect(**db_params)

    # 创建一个游标对象
    cursor = connection.cursor()

    # 执行查询
    cursor.execute('SELECT * FROM statistic_graph')

    # 获取所有结果行
    rows = cursor.fetchall()

    # 打印结果
    for row in rows:
        print(row)

except (Exception, psycopg2.Error) as error:
    print('Error while connecting to PostgreSQL:', error)

finally:
    # 关闭游标和数据库连接
    if connection:
        cursor.close()
        connection.close()
